'use strict';
const {
    Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
    class Category extends Model {
        /**
         * Helper method for defining associations.
         * This method is not a part of Sequelize lifecycle.
         * The `models/index` file will call this method automatically.
         */
        static associate(models) {
            // define association here
            models.Category.hasMany(models.Category, {as: 'children', foreignKey: 'parentId'})  // 每个一级分类有很多二级分类
        }
    };
    Category.init({
        parentId: DataTypes.INTEGER,
        name: DataTypes.STRING,
        image: DataTypes.STRING,
        sort: DataTypes.INTEGER
    }, {
        sequelize,
        modelName: 'Category',
    });
    return Category;
};